var app = getApp()
var baseutil = require('../../utils/baseutil.js');
var config = require('../../utils/config.js');
var netutil = require('../../utils/netutil.js');
let { WeToast } = require('../../src/wetoast.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userHead: null,
    nickName: null,
    TUserInfo: null,//用户信息
    isLogin:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var THIS = this;
    wx.getStorage({
      key: 'userHead',
      success: function (res) {
        THIS.setData({
          userHead: res.data
        })
      },
      fail: function (res) {
        console.log(res.errMsg);
      }
    }),
      wx.getStorage({
        key: 'nickName',
        success: function (res) {
          THIS.setData({
            nickName: res.data
          })
        },
        fail: function (res) {
          console.log(res.errMsg);
        }
      })
    
    //创建可重复使用的toast实例，并附加到this上，通过this.wetoast访问
    new app.WeToast()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      TUserInfo: app.globalData.TUserInfo,
      isLogin:app.globalData.isLogin
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  bindPhone: function () {
    wx.navigateTo({
      url: '../bindphone/bindphone'
    })
  },
  updateData: function (TUserInfo) {
    baseutil.log("绑定成功")
    this.setData({
      TUserInfo: TUserInfo
    })
  },
  standard: function () {
    if (!this.data.isLogin) {
      this.wetoast.toast({
        title: '请先绑定!',
        duration: 500
      })
      setTimeout(function () {
        wx.navigateTo({ url: '/pages/bindphone/bindphone' })
      }, 500)

      return;
    }
    wx.navigateTo({
      url: '../standard/standard',
    })

  },
  goPassengerList: function () {
    if (!this.data.isLogin) {
      this.wetoast.toast({
        title: '请先绑定!',
        duration: 500
      })
      setTimeout(function () {
        wx.navigateTo({ url: '/pages/bindphone/bindphone' })
      }, 500)

      return;
    }
    wx.navigateTo({
      url: '../passenger/passengerList/passengerList',
    })

  },
  flightorder: function () {
    if (!this.data.isLogin) {
      this.wetoast.toast({
        title: '请先绑定!',
        duration: 500
      })
      setTimeout(function () {
        wx.navigateTo({ url: '/pages/bindphone/bindphone' })
      }, 500)

      return;
    }
    wx.navigateTo({
      url: '../myOrder/myOrder?type=' + 0,
    })
  },
  trainorder: function () {
    if (!this.data.isLogin) {
      this.wetoast.toast({
        title: '请先绑定!',
        duration: 500
      })
      setTimeout(function () {
        wx.navigateTo({ url: '/pages/bindphone/bindphone' })
      }, 500)

      return;
    }
    wx.navigateTo({
      url: '../myOrder/myOrder?type=' + 1,
    })
  },
  allorder: function () {
    if (!this.data.isLogin) {
      this.wetoast.toast({
        title: '请先绑定!',
        duration: 500
      })
      setTimeout(function () {
        wx.navigateTo({ url: '/pages/bindphone/bindphone' })
      }, 500)

      return;
    }
    wx.navigateTo({
      url: '../myOrder/myOrder?type=' + 0 ,
    })
  },
  goPhone() {
    wx.makePhoneCall({
      phoneNumber: '400-720-9939'
    })
  }  ,
  internationalTicketOrder() {
    this.wetoast.toast({
      title: '该功能尚未开通,敬请期待!',
      duration: 1000
    })
  }, hotelOrder() {
    this.wetoast.toast({
      title: '该功能尚未开通,敬请期待!',
      duration: 1000
    })
  }
})